// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class RainEffectController extends cc.Component {

    @property(cc.EffectAsset)
    effectAsset: cc.EffectAsset = null;

    private _time: number = 0;

    onLoad() {
        this._useRainEffect();
    }

    _useRainEffect() {
        let material = cc.Material.create(this.effectAsset);
        this._time = 0;
        let mat1 = this.node.getComponent(cc.Sprite).sharedMaterials[0];
        if (mat1) {
            mat1 = material;
        }
    }

    update(dt) {
        this._time += dt;
        let material = this.node.getComponent(cc.Sprite).sharedMaterials[0];
        material.setProperty('u_time', this._time);
    }
}
